/*Name:Yifu Diao
 *Dec 8,2010
 *15600-HW9 
 * */
package edu.cmu.cs.task7.model;

import java.util.HashMap;

import com.ebay.sdk.ApiContext;
import com.ebay.sdk.ApiException;
import com.ebay.sdk.SdkException;
import com.ebay.sdk.call.GetItemCall;
import com.ebay.sdk.call.GetMyeBaySellingCall;
import com.ebay.sdk.call.GetSellerListCall;
import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
import com.ebay.soap.eBLBaseComponents.ItemListCustomizationType;
import com.ebay.soap.eBLBaseComponents.ItemType;

public class GetAllItemsModel {
	 private ApiContext apiContext=new ApiContext();	 
	 
     public GetAllItemsModel(ApiContext apiContext)  throws Exception{
    	 this.apiContext=apiContext;
     }
     
     public HashMap getAllItems() throws ApiException, SdkException, Exception{
    	 GetMyeBaySellingCall api = new GetMyeBaySellingCall(this.apiContext);
    	 
    	 ItemListCustomizationType itemListType =  new ItemListCustomizationType();
         itemListType.setInclude(Boolean.TRUE);
         //Optional:setSort, setPagination
         
         api.setActiveList(itemListType);
         api.setScheduledList(itemListType);
         api.setSoldList(itemListType);
         api.setUnsoldList(itemListType);
    	 
         api.getMyeBaySelling();
    	 
         //
         ItemType[] tempActiveItems = null;
         if (api.getReturnedActiveList()!=null)
       	  tempActiveItems= (api.getReturnedActiveList().getItemArray()).getItem();
         final ItemType[] activeItems = tempActiveItems;
         
         ItemType[] tempUnSoldItems = null;
         if (api.getReturnedUnsoldList()!=null )
       		  tempUnSoldItems =  (api.getReturnedUnsoldList().getItemArray()).getItem();
         final ItemType[] unSoldItems = tempUnSoldItems;
         
         HashMap AllItems=new HashMap();
         AllItems.put("active",activeItems );
         AllItems.put("unsold",unSoldItems );
         
         return AllItems;
    	 
     }
     
}
